<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.js"></script>
    <script>
        // Generator 部署ajax操作，让异步代码同步化
        function* main(){
            console.log('start');
            let res = yield request('https://csss.sf-team.cn');

            console.log(res);

            console.log('数据加载失败');
        }

        const ite = main();
        ite.next();
        function request(url){
            $.ajax({
                url:url,
                method:'get',
                error(res){
                    ite.next(res);
                }
            })
        }

        // 加载loading... 页面
        // 数据加载完成... (异步操作)
        // loading关闭
        function* load(){
            loadUI();
            yield showData();
            hideUI();
        }

        let itLoad = load();
        itLoad.next();
        function loadUI(){
            console.log('加载loading...页面');
        }
        function showData(){
            // 模拟异步操作
            setTimeout(() => {
                console.log('数据加载完成');
                itLoad.next();
            },1000);
        }
        function hideUI(){
            console.log('隐藏loading...页面')
        }
    </script>
</body>
</html>